<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Http\Resources\Json\JsonResource;
class IllegalCollection extends JsonResource
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
//        return parent::toArray($request);
        return [
            'id' => $this->id,
            'car_id' => $this->car_id,
            'plate_number' => $this->plate_number,
            'car_name' => $this->car_name,
            // 已收款未处理
            'processed' => $this->where('plate_number',$this->plate_number)->where('type',1)->count(),
            // 未收款未处理
            'untreated' => $this->where('plate_number',$this->plate_number)->where('type',0)->count(),
            // 已收款已处理
            'commite' => $this->where('plate_number',$this->plate_number)->where('type',2)->count(),
            // 未收款已处理
            'uncleared' => $this->where('plate_number',$this->plate_number)->where('type',3)->count(),
        ];
    }
}
